<template>
    <div class="tool-item" :style="`${Children?'padding-left: 40px;': ''}${border?'border-top: 1px solid #fff;':''}`">
        <div class="tool-item_left">
            <div class="tool-header">
                <div class="tool-name">{{ tool.name }}</div>
                <div class="tool-description">{{ tool.description }}</div>
            </div>
            <div class="tool-meta">
                <div class="tool-params">
                    <el-tag color="#e9e9e9" :hit="false" size="small" v-for="(param, paramIndex) in tool.params" :key="paramIndex" class="param" type="info">{{ param }}</el-tag>
                    <a href="#" class="param-link">参数 查看示例</a>
                </div>
                <div class="meta-item">
                    <div class="meta-item_left" v-if="!Children">
                        <el-icon color="#007BFF" size="16"><HelpFilled /></el-icon>
                        <div class="meta-item_left_text">
                            <span>{{ tool.meta.creator }}</span>
                            <span>发布于 {{ tool.meta.date }}</span>
                        </div>
                    </div>
                    <div class="meta-item_right">
                        <div class="meta-item_right_text">
                            <el-icon color="#CCC" size="16"><HelpFilled /></el-icon>
                            <span>{{ tool.meta.memory }}M</span>
                        </div>
                        <div class="meta-item_right_text">
                            <el-icon color="#CCC" size="16"><HelpFilled /></el-icon>
                            <span>{{ tool.meta.users }}k</span>
                        </div>
                        <div class="meta-item_right_text">
                            <el-icon color="#CCC" size="16"><HelpFilled /></el-icon>
                            <span>{{ tool.meta.time }}ms</span>
                        </div>
                        <div class="meta-item_right_text">
                            <el-icon color="#CCC" size="16"><HelpFilled /></el-icon>
                            <span>{{ tool.meta.progress }}%</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="tool-item_right" v-if="Children">
            <el-button type="primary" @click="add()" plain>添加</el-button>
        </div>
    </div>
</template>

<script>
export default{
    props: {
        Children: {
            type: Boolean,
            default: false
        },
        border: {
            type: Boolean,
            default: true
        },
        tool: {
            type: Object,
            default: () => {}
        },
    },
    data() {
        return {

        }
    },
    methods: {
        add() {
            this.$emit("add", this.tool)
        }
    },
}
</script>

<style scoped lang="scss">

.tool-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;

    &_left{
        .tool-header {
            margin-bottom: 10px;

            .tool-name {
                font-size: 18px;
                font-weight: bold;
            }
            
            .tool-description {
                font-size: 14px;
                color: #666;
            }
        }
        .tool-meta {
            font-size: 12px;
            color: #999;
            margin-bottom: 10px;

            .tool-params {
                font-size: 12px;
                color: #666;
                margin-bottom: 10px;

                .param {
                    margin-right: 10px;
                }
                
                .param-link {
                    color: #007BFF;
                    text-decoration: none;
                }
            }
        }

        .meta-item {
            margin-right: 15px;
            display: flex;
            align-items: center;
            padding-right: 100px;
            justify-content: space-between;

            &_left{
                display: flex;
                align-items: center;

                &_text{
                    margin-left: 5px;
                    display: flex;
                    align-items: center;

                    span{
                        line-height: 12px;
                        padding-right: 15px;
                        position: relative;

                        &:before{
                            content: "";
                            display: block;
                            width: 1px;
                            height: 10px;
                            top: 2px;
                            background-color: #ccc;
                            position: absolute;
                            right: 7px;

                            
                        }
                        &:last-child{
                            &:before{
                                display: none;
                            }
                        }
                    }
                }
            }
            &_right{
                display: flex;
                align-items: center;

                &_text{
                    display: flex;
                    align-items: center;
                    line-height: 12px;
                    padding-right: 15px;
                    position: relative;

                    span{
                        margin-left: 5px;
                    }

                    &:before{
                        content: "";
                        display: block;
                        width: 1px;
                        height: 10px;
                        top: 2px;
                        background-color: #ccc;
                        position: absolute;
                        right: 7px;

                        
                    }
                    &:last-child{
                        &:before{
                            display: none;
                        }
                    }
                }
            }
        }

        .add-button {
            background-color: #007BFF;
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 3px;
            cursor: pointer;
        }
    }
    &_right{
        padding-right: 50px;
    }
}
</style>

